const api = require('../../network/api')
Page({
    data: {
        scrollTop: 0,
        banners: [],
        details: [],
        navFlag: false,
        tabs: [{
                icon: '/assets/img/list.png',
                text: '排行榜',
                type: 'list'
            },
            {
                icon: '/assets/img/vip.png',
                text: '会员专区',
                type: 'vip'
            },
            {
                icon: '/assets/img/novel.png',
                text: '小说',
                type: 'novel'
            },
            {
                icon: '/assets/img/cartoon.png',
                text: '动漫',
                type: 'cartoon'
            },
            {
                icon: '/assets/img/hot.png',
                text: '热门',
                type: 'hot'
            }

        ]
    },
    onLoad(o) {},
    onShow() {
        this.init()

    },
    // 初始化首页内容
    async init() {
        const res = await api.getHomeData()
        if (res.code == 200) {
            const { banners, details } = res.data
            this.setData({
                banners,
                details
            })
        }
    },
    onEvent(e) {
        let id = e.detail.id
        wx.navigateTo({
            url: `/pages/detail/index?id=${id}`,
        })
    },
    onDetail(e) {
        // console.log(e);
        let id = e.currentTarget.dataset.id
        wx.navigateTo({
            url: `/pages/detail/index?id=${id}`,
        })

    },
    onSearch() {
        wx.navigateTo({
            url: '/pages/search/index',
        })
    },
    // 根据不同类型进入页面
    onPage(e) {
        const { type } = e.currentTarget.dataset
        switch (type) {
            case 'list':
                console.log(type, 'type');
                break
            case 'vip':
                console.log(222);
                break
            case 'novel':
                wx.navigateTo({
                    url: '/pages/novel/index',
                })
                break
            case 'cartoon':
                console.log(type, 'type');
                break
            case 'hot':
                console.log(type, 'type');
                break
        }
    },
    lower() {

    },
    scroll(e) {
        // console.log(e, 'scroll')
        let scrollTop = e.detail.scrollTop
        if (scrollTop >= 110) {
            this.setData({
                navFlag: true
            })
        } else {
            this.setData({
                navFlag: false
            })
        }
    },
    scrollToTop() {
        this.setData({
            scrollTop: 0
        })
    },
})